package com.weifangfirecontrolformal.weifangfirecontrolformal.web.service.business.businessdetail;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.weifangfirecontrolformal.weifangfirecontrolformal.common.base.BaseService;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.model.RespEntity;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.utils.requestutil.HttpRequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BusinessDetailService extends BaseService {

	private static final Logger logger = LoggerFactory.getLogger(BusinessDetailService.class);

	/**
	 * 详情页面数据统计
	 * @param
	 * @return
	 */
	public RespEntity statistics(JSONObject jsonParam) {
		jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
		//统计数据
		com.alibaba.fastjson.JSONObject statistics = makeData(jsonParam,"businessJava","config","statistics","businessDetail");
		if(StrUtil.isNotBlank(statistics.getString("methodCodeFlag"))) return RespEntity.expire();
		if(StrUtil.isNotBlank(statistics.getString("methodErrorFlag"))) return RespEntity.fail(statistics.getString("msg"));
		//单位详情
		com.alibaba.fastjson.JSONObject businessDetail = makeData(jsonParam,"businessJava","config","detail","business");
		if(StrUtil.isNotBlank(businessDetail.getString("methodCodeFlag"))) return RespEntity.expire();
		if(StrUtil.isNotBlank(businessDetail.getString("methodErrorFlag"))) return RespEntity.fail(businessDetail.getString("msg"));
		//结果转驼峰
		//JSONObject businessDetailN = JSONUtil.parseObj(JsonKeyEdit.jsonKeyEdit(businessDetail.toJSONString()));
		StringBuilder detailStr = new StringBuilder("行政区划：" + businessDetail.getString("areaName") + ";" +
				"详细位置：" + businessDetail.getString("addr") + ";" +
				"消防等级：" + businessDetail.getString("fireRatingName") + ";" +
				"单位性质：" + businessDetail.getString("unitPropertyName") + ";" +
//				"所属行业：" + businessDetail.getString("industryName") + ";" +
				"单位类别：" + businessDetail.getString("unitCategoryName") + ";" +
				"消防第一责任人姓名：" + businessDetail.getString("oneResponPersonName") + ";" +
				"消防第一责任人电话：" + businessDetail.getString("oneResponPersonPhone") + ";");
		if (businessDetail.containsKey("businessCustomizeManagePersonList")){
			JSONArray jsonArray = businessDetail.getJSONArray("businessCustomizeManagePersonList");
			for (Object obj : jsonArray){
				com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) obj;
				detailStr.append(jsonObject.getString("typeName")).append("姓名：").append(jsonObject.getString("personName")).append(";").append(jsonObject.getString("typeName")).append("电话：").append(jsonObject.getString("personPhone")).append(";");
			}
		}
		statistics.put("businessDetail", detailStr.toString());
		return RespEntity.success(statistics);
	}

}
